# Maintainer: Manuel Naranjo <naranjo.manuel@gmail.com>

_pyname=psutil
_realname=${_pyname}
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=5.8.0
pkgrel=1
pkgdesc="A cross-platform process and system utilities module for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/giampaolo/psutil"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('staticlibs' 'strip' '!debug')
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/giampaolo/psutil/archive/release-${pkgver}.tar.gz"
        "0001-mingw-fixes-without-loadlib.patch")
sha256sums=('c015248da36109ffaa15f46fce8c0003f678cfaa408090f466c80318885e7abf'
            'ec71cb0952e3422f1f67c04cdf67799291bba17292af1fe259bc8e31d9dc5ade')

prepare() {
  cd "${srcdir}"/${_realname}-release-${pkgver}
  patch -p1 -i "${srcdir}/0001-mingw-fixes-without-loadlib.patch"

  cd ${srcdir}
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-release-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py check
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"
}
